using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyBullet : MonoBehaviour
{
    public float speed;
    public GameObject Player;
    private Rigidbody2D rigid;

    void Start()
    {
        StartCoroutine(DisPlay());
        Player = GameObject.Find("Player");
        transform.right = (Player.transform.position - transform.position).normalized;
        rigid = GetComponent<Rigidbody2D>();
        rigid.velocity = transform.right * speed;
    }

    public IEnumerator DisPlay()
    {
        yield return new WaitForSeconds(3);
        if (gameObject) Destroy(gameObject);
    }

    public void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.layer == LayerMask.NameToLayer("Player") || collision.gameObject.layer == LayerMask.NameToLayer("Wall"))
        {
            Destroy(gameObject);
        }
    }
}
